<template>
  <div class="wait_allot">
    <dt-search ref="search" :labelWidth="100" :xl=8>
      <Button type="primary" style="margin-left: 8px" v-if="unlocking('0213030305')"
        @click="revocation()">撤销分配</Button>
      <Button type="primary" style="margin-left: 8px" v-if="unlocking('0213030306')"
        @click="revocation('all')">撤销全部分配</Button>
    </dt-search>
    <div class="wait_tips">手动分配线索后有30分钟的撤回期，30分钟后将会直接推送到相应案场或顾问</div>
    <dt-grid ref="table" page :onFetch='onFetch' :select='select' />
  </div>
</template>

<script>
  import columnOpt from '../opt/detailColumns'
  import clueImportMgr from '@/biz/customer/clueImport'
  import searchOpt from '../opt/detailSearch'

  export default {
    components: {},
    data() {
      return {
        name: 'wait_Allot',
        select: {
          change: (e) => { this.tableChange(e) },
        },
        selectData: [],
        choosedLength: 0,
        info: {
          companyIds: [],
          buildingId: ''
        }
      }
    },
    methods: {
      revocation(type = '') {
        if (type != 'all' && !this.choosedLength) return this.$Message.warning('请先勾选要删除的线索')
        this.$Modal.confirm({
          title: '提示',
          content: `撤销分配后将进入待分配列表，是否确认要撤销？`,
          okText: '确认',
          closable: true,
          onOk: () => {
            let params = {
              batchId: this.$route.query.batchId
            }
            if (type == 'all') {
              console.log('撤销全部分配')
              params.ids = []
            } else {
              params.ids = this.selectData
            }
            clueImportMgr.cancelByIds(params).then(res => {
              this.$Message.success('撤销成功')
              this.$refs.table.fetch(true)
            })
          }
        })
      },
      //表格选中
      tableChange(val) {
        this.selectData = []
        if (val && val.length) {
          this.choosedLength = val.length
          val.forEach((item) => {
            if (item.id) {
              this.selectData.push(Number(item.id))
            }
          })
        } else {
          this.selectData = []
          this.choosedLength = 0
        }
      },
      onFetch(data) {
        let params = {
          ...data,
          batchId: Number(this.$route.query.batchId),
          type: 1
        }
        return clueImportMgr.getOperationDetailList(params).then(res => {
          this.totalNum = res.total
          res.list = res.records
          return res
        })
      },
    },
    mounted() {
      this.$refs.table.init(this, new columnOpt.ColumnAllot(this))
      this.$refs.search.init(this.$refs.table, new searchOpt(this), this.info)
      this.$refs.table.fetch()
    }
  }
</script>

<style lang="scss" scoped>
  .wait_allot {
    .flex_btn {
      button {
        margin-left: 10px;
      }
    }

    .wait_tips {
      color: #F59A23;
      margin-bottom: 20px;
    }
  }
</style>